<template>
	<view class="main">
		<view class="active_tit">
			<view class="tit">
				建筑类
			</view>
			<!-- <view class="add">
				＋
			</view> -->
		</view>
		<!-- input -->
		<ActiveForm required ref='industryQualifi'>
			<view class="active_label">
				行业资质：
			</view>
			<view class="active_input">
				<SelectPicker v-model="stdOffsurConstruction.industryQualifi" :options="industryQualifiOption" placeholder="请选择" />
			</view>
		</ActiveForm>

		<ActiveForm required ref='turnover12month'>
			<view class="active_label">
				近12个月工程额（元）：
			</view>
			<view class="active_input">
				<mInput maxlength="16" type="number" v-model="stdOffsurConstruction.turnover12month" />
			</view>
		</ActiveForm>

		<ActiveForm required ref='qualifiType'>
			<view class="active_label">
				资质类型：
			</view>
			<view class="active_input">
				<SelectPicker v-model="stdOffsurConstruction.qualifiType" :options="qualifiTypeOption" placeholder="请选择" />
			</view>
		</ActiveForm>

		<ActiveForm required ref='marginRate'>
			<view class="active_label">
				综合毛利率（%）：
			</view>
			<view class="active_input">
				<mInput type="number" v-model="stdOffsurConstruction.marginRate" />
			</view>
		</ActiveForm>

		<ActiveForm required ref='turnoverLast12'>
			<view class="active_label">
				近13-24个月工程额（元）：
			</view>
			<view class="active_input">
				<mInput maxlength="16" type="number" v-model="stdOffsurConstruction.turnoverLast12" />
			</view>
		</ActiveForm>
		<ActiveForm required ref='nextYearTurnover'>
			<view class="active_label">
				预计未来一年营业额（元）：
			</view>
			<view class="active_input">
				<mInput maxlength="16" type="number" v-model="stdOffsurConstruction.nextYearTurnover" />
			</view>
		</ActiveForm>



		<view class="active_tit">
			<view class="tit2 required">
				项目信息（前三大项目）
			</view>
		</view>

		<block v-for="(item,index) in stdOffsurConstructionProject" :key='index'>
			<view class="cut">项目信息{{index+1}}
				<uni-icons class="clear" type="clear" @click='stdDel(stdOffsurConstructionProject,item,"stdOffsurConstructionProject")'></uni-icons>
			</view>
			<ActiveForm required ref=''>
				<view class="active_label">
					项目名称：
				</view>
				<view class="active_input">
					<input type="text" v-model="item.projectName" />
				</view>
			</ActiveForm>
			<ActiveForm required ref=''>
				<view class="active_label">
					发包企业：
				</view>
				<view class="active_input">
					<input type="text" v-model="item.contractComp" />
				</view>
			</ActiveForm>
			<ActiveForm required ref=''>
				<view class="active_label">
					发包企业类型：
				</view>
				<view class="active_input">
					<SelectPicker v-model="item.contractCompTye" :options="contractCompOption" placeholder="请选择" />
				</view>
			</ActiveForm>
			<ActiveForm required ref=''>
				<view class="active_label">
					与客户合作年限（年）：
				</view>
				<view class="active_input">
					<mInput :thousand='false' type="text" v-model="item.cooperationYear" />
				</view>
			</ActiveForm>
			<ActiveForm required ref=''>
				<view class="active_label">
					项目工期（月）：
				</view>
				<view class="active_input">
					<mInput :thousand='false' type="number" v-model="item.projectPeriod" />
				</view>
			</ActiveForm>
			<ActiveForm required ref=''>
				<view class="active_label">
					完成进度（%）：
				</view>
				<view class="active_input">
					<mInput type="number" v-model="item.finishRatio" />
				</view>
			</ActiveForm>
			<ActiveForm required ref=''>
				<view class="active_label">
					合同金额（元）：
				</view>
				<view class="active_input">
					<mInput maxlength="16" type="number" v-model="item.surplusAmount" />
				</view>
			</ActiveForm>
			<!-- <ActiveForm required  ref=''>
				<view class="active_label">
					已计量工程款（元）：
				</view>
				<view class="active_input">
					<input :disabled="true" maxlength="16" type="number" disabled v-model="(item.measuredFunds=item.surplusAmount/item.finishRatio).toFixed(2)" />
				</view>
			</ActiveForm> -->
			<ActiveForm required ref=''>
				<view class="active_label">
					已收工程款（元）：
				</view>
				<view class="active_input">
					<mInput maxlength="16" type="number" v-model="item.receivedFunds" />
				</view>
			</ActiveForm>
			<ActiveForm required ref=''>
				<view class="active_label">
					未收工程款（元）：
				</view>
				<view class="active_input">
					<mInput maxlength="16" type="number" disabled :value="gck(item)" />
				</view>
			</ActiveForm>
			<ActiveForm required ref=''>
				<view class="active_label">
					结算方式：
				</view>
				<view class="active_input">
					<input type="text" v-model="item.settlement" />
					<!-- <SelectPicker  v-model="item.settlement" :options="settlementOption" placeholder="请选择" /> -->
				</view>
			</ActiveForm>
		</block>
		<view class="active_tit">
			<view class="" style="display: flex;">
				<view class="add" @click="add">
					新增项目信息
				</view>
			</view>
		</view>
		<view class="active_tit">
			<view class="tit2 required">
				主要上游（前三大客户）
			</view>
			<!-- <view class="add" @click="adds">
				＋
			</view> -->
		</view>

		<block v-for="(item,index) in stdOffsurConstructionMainCust" :key='index+100'>
			<view class="cut">主要上游{{index+1}}
				<uni-icons class="clear" type="clear" @click='stdDel(stdOffsurConstructionMainCust,item,"stdOffsurConstructionMainCust")'></uni-icons>
			</view>
			<view class="main">
				<ActiveForm required ref=''>
					<view class="active_label">
						序号：
					</view>
					<view class="active_input">
						<input type="text" :disabled="true" v-model="item.xh" />
					</view>
				</ActiveForm>
				<ActiveForm required ref=''>
					<view class="active_label">
						客户名称：
					</view>
					<view class="active_input">
						<input type="text" v-model="item.custName" />
					</view>
				</ActiveForm>
				<ActiveForm required ref=''>
					<view class="active_label">
						交易产品：
					</view>
					<view class="active_input">
						<input type="text" v-model="item.transaction" />
					</view>
				</ActiveForm>
				<ActiveForm required ref=''>
					<view class="active_label">
						近12个月交易数量：
					</view>
					<view class="active_input">
						<mInput  type="number" v-model="item.count12month" />
					</view>
				</ActiveForm>
				<ActiveForm required ref=''>
					<view class="active_label">
						近12个月交易金额（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="item.turnover12month" />
					</view>
				</ActiveForm>

				<ActiveForm required ref=''>
					<view class="active_label">
						结算方式：
					</view>
					<view class="active_input">

						<SelectPicker v-model="item.settlement" :options="settlementOption" placeholder="请选择" />
					</view>
				</ActiveForm>
				<ActiveForm required ref=''>
					<view class="active_label">
						账期（月）：
					</view>
					<view class="active_input">
						<mInput :thousand='false' type="number" v-model="item.accountPeriod" />
					</view>
				</ActiveForm>
				<ActiveForm required ref=''>
					<view class="active_label">
						合作年限（月）：
					</view>
					<view class="active_input">
						<mInput :thousand='false'  v-model="item.cooperationYear" />
					</view>
				</ActiveForm>
			</view>
		</block>
		<view class="active_tit">
			<view class="" style="display: flex;">
				<view class="add" @click="adds">
					新增主要上游
				</view>
			</view>
		</view>
		<view class="active_tit">
			<view class="tit2">
				毛利率信息
			</view>
		</view>
		<block v-for="(zitem,index) in mllForm" :key='zitem.busiType+index'>
			<view class="main">
				<ActiveForm  ref=''>
					<view class="active_label">
						业务类型：
					</view>
					<view class="active_input">
						<!-- <span>{{item.busiType}}</span> -->
						<SelectPicker v-model="zitem.busiType" :disabled="true" :options="mlloption" placeholder="请选择" />
					</view>
				</ActiveForm>
				<ActiveForm  ref=''>
					<view class="active_label">
						近12月营业额（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" v-model="zitem.turnover12Month" />
					</view>
				</ActiveForm>
				<ActiveForm  ref=''>
					<view class="active_label">
						近12月开票额（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" v-model="zitem.invoice12month" />
					</view>
				</ActiveForm>
				<ActiveForm  ref=''>
					<view class="active_label">
						建材成本/年（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="zitem.materialCost" />
					</view>
				</ActiveForm>
				<ActiveForm  ref=''>
					<view class="active_label">
						劳务成本/年（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="zitem.labourCost" />
					</view>
				</ActiveForm>
				<ActiveForm  ref=''>
					<view class="active_label">
						挂靠费成本/年（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="zitem.affiliationCost" />
					</view>
				</ActiveForm>
				<ActiveForm  ref=''>
					<view class="active_label">
						其他成本/年（元）：
					</view>
					<view class="active_input">
						<mInput maxlength="16" type="number" v-model="zitem.otherCost" />
					</view>
				</ActiveForm>
				<!-- <ActiveForm required  ref='outPrice'  v-if="zitem.marginRate==='NaN'">
					<view class="active_label">
						毛利率（%）：
					</view>
					<view class="active_input">
						<input maxlength="16" disabled type="number" v-model.number="zitem.marginRate=0" />
					</view>
				</ActiveForm> -->
				<ActiveForm  ref=''>
					<view class="active_label">
						毛利率（%）：
					</view>
					<view class="active_input">
						<input disabled :value="zmarginRate(zitem)" />
					</view>
				</ActiveForm>
			</view>
		</block>
		<view class="main">
			<view class="active_tit">
				<view class="tit2">
					毛利率合计
				</view>
			</view>

			<ActiveForm  ref=''>
				<view class="active_label">
					近12月营业额（元）：
				</view>
				<view class="active_input">
					<mInput :disabled="true" v-model="mllHj.turnover12month" />
				</view>
			</ActiveForm>
			<ActiveForm  ref=''>
				<view class="active_label">
					近12月开票额（元）：
				</view>
				<view class="active_input">
					<mInput type="number" :disabled="true" v-model="mllHj.invoice12month" />
				</view>
			</ActiveForm>
			<ActiveForm  ref=''>
				<view class="active_label">
					建材成本/年（元）：
				</view>
				<view class="active_input">
					<mInput type="number" :disabled="true" v-model="mllHj.materialCost" />
				</view>
			</ActiveForm>
			<ActiveForm  ref=''>
				<view class="active_label">
					劳务成本/年（元）：
				</view>
				<view class="active_input">
					<mInput type="number" :disabled="true" v-model="mllHj.labourCost" />
				</view>
			</ActiveForm>
			<ActiveForm  ref=''>
				<view class="active_label">
					挂靠费成本/年（元）：
				</view>
				<view class="active_input">
					<mInput type="number" :disabled="true" v-model="mllHj.affiliationCost" />
				</view>
			</ActiveForm>
			<ActiveForm  ref=''>
				<view class="active_label">
					其他成本/年（元）：
				</view>
				<view class="active_input">
					<mInput type="number" :disabled="true" v-model="mllHj.otherCost" />
				</view>
			</ActiveForm>
			<ActiveForm  ref=''>
				<view class="active_label">
					加权平均毛利（%）：
				</view>
				<view class="active_input">
					<mInput :disabled="true" v-model="mllHj.marginRate" />
				</view>
			</ActiveForm>
		</view>


		<!-- <button type="default" @click="getForm">getForm</button> -->
	</view>
</template>

<script>
	import SelectPicker from "../../../SelectPicker";
	export default {

		name: 'activeForm',
		data() {
			return {
				Cflag:false,
				province: "",
				city: "",
				county: "",
				index: 1,
				mllHj: {
					marginRate: '',
					turnover12month:'',
					invoice12month:'',
					materialCost:'',
					labourCost:'',
					affiliationCost:'',
					otherCost:'',
				},
				mllForm: [],
				stdOffsurConstruction: {
					businessId: "", //业务申请流水号
					createTime: "", //创建时间
					createUser: "", //创建人
					customerId: "", //客户编号
					customerSystemId: "", //客户系统编号
					deleteFlag: "", //删除标志
					entId: "", //企业ID
					entityRoleType: "", //数据归属类型
					getDatTime: "", //数据加载时间
					imageUrl: "", //影像路径
					industryQualifi: "", //行业资质
					marginRate: 0, //综合毛利率（%）
					qualifiType: "", //资质类型
					reqId: "", //业务申请序号
					sourceSystem: "", //数据来源系统
					turnover12month: 0, //近12个月工程额（元）
					turnoverLast12: 0, //近13-24个月工程额（元）
					updateTime: "", //更新时间
					updateUser: "", //更新人
					uuid: "" //uuid
				},
				stdOffsurConstructionProject: [{
					businessId: "", //业务申请流水号
					contractComp: "", //发包企业
					contractCompTye: "", //发包企业类型
					cooperationYear: 0, //与客户合作年限
					createTime: "", //创建时间
					createUser: "", //创建人
					customerId: "", //客户编号
					customerSystemId: "", //客户系统编号
					deleteFlag: "", //删除标志
					entId: "", //企业ID
					entityRoleType: "", //数据归属类型
					finishRatio: 0, //完成进度（%）
					getDatTime: "", //数据加载时间
					imageUrl: "", //影像路径
					measuredFunds: 0, //已计量工程款（元）
					notReceivedFunds: 0, //未收工程款（元）
					projectName: "", //项目名称
					projectPeriod: 0, //项目工期（月）
					receivedFunds: 0, //已收工程款（元）
					reqId: "", //业务申请序号
					settlement: "", //结算方式
					sourceSystem: "", //数据来源系统
					surplusAmount: 0, //剩余合同金额（元）
					updateTime: "", //更新时间
					updateUser: "", //更新人
					uuid: "" //uuid
				}],
				stdOffsurConstructionMainCust: [{
					accountPeriod: 0, //账期（月）
					businessId: "", //业务申请流水号
					cooperationYear: 0, //合作年限（月）
					count12month: 0, //近12个月交易数量
					createTime: "", //创建时间
					createUser: "", //创建人
					custName: "", //客户名称
					customerId: "", //客户编号
					customerSystemId: "", //客户系统编号
					deleteFlag: "", //删除标志
					entId: "", //企业ID
					entityRoleType: "", //数据归属类型
					getDatTime: "", //数据加载时间
					imageUrl: "", //影像路径
					reqId: "", //业务申请序号
					settlement: "", //结算方式
					sourceSystem: "", //数据来源系统
					transaction: "", //交易产品
					turnover12month: 0, //近12个月交易金额（元）
					updateTime: "", //更新时间
					updateUser: "", //更新人
					uuid: "", //uuid
					xh: "" //序号
				}],
				industryQualifiOption: [],
				qualifiTypeOption: [],
				contractCompOption: [],
				settlementOption: [],
				mlloption: [],
			}
		},
		components: {
			SelectPicker

		},
		computed: {
			gck() {
				return function(item) {
					item.notReceivedFunds=(Number(item.surplusAmount)*Number(item.finishRatio)/100-Number(item.receivedFunds)).toFixed(2)
			        return item.notReceivedFunds
				}
			},
			zmarginRate() {
				return function(zitem) {
					//debugger
					//zitem.marginRate	
					if (Number(zitem.turnover12Month) <= 0) {
						zitem.marginRate = 0
						return 0
					} else {
						let lv = ((1 - (Number(zitem.materialCost) + Number(zitem.labourCost) + Number(zitem.affiliationCost) + Number(
							zitem.otherCost)) / Number(zitem.turnover12Month)) * 100).toFixed(2)
						zitem.marginRate = lv
						return lv
					}

					

				}
			}
		},
		watch: {
			stdOffsurConstruction: {
				handler: function(res) {
					//console.warn('stdOffsurConstruction组件数据变化',res)
					getApp().globalData.stdOffsurConstruction = res
				},
				deep: true
			},
			stdOffsurConstructionProject: {
				handler: function(res) {
					//console.warn('stdOffsurConstructionProject组件数据变化',res)
					if(this.Cflag){
						getApp().globalData.stdOffsurConstructionProject = res
					}
					
				},
				deep: true
			},
			stdOffsurConstructionMainCust: {
				handler: function(res) {
					//console.warn('stdOffsurConstructionMainCust组件数据变化',res)
					getApp().globalData.stdOffsurConstructionMainCust = res
				},
				deep: true
			},
			mllForm: {
				handler: function(res) {
					//debugger
					//console.warn('mll数据变化',res)
					//debugger
					getApp().globalData.stdOffsurConstructionMargin = res
					setTimeout(() => {
						this.lvhj()
					}, 0)


				},
				deep: true
			},
		},
		mounted() {
			//获取返显数据
			setTimeout(() => {
				this.Cflag = true

				//获取下拉类型
				//婚姻状况

				this.maritalStatusOptions = getApp().globalData.optType.MARITAL //婚姻状况
				this.qualifiTypeOption = getApp().globalData.optType.QUALIFY //资质类型
				this.contractCompOption = getApp().globalData.optType.CON_TYPE //发包企业类型
				this.settlementOption = getApp().globalData.optType.SETTLE //结算方式
				this.mlloption = getApp().globalData.optType.CONS_BUSITYPE //业务类型
				this.industryQualifiOption = getApp().globalData.optType.INDUSTRY_QUALIFI
				this.stdOffsurConstruction = getApp().globalData.stdOffsurConstruction
				this.stdOffsurConstructionProject = getApp().globalData.stdOffsurConstructionProject
				this.stdOffsurConstructionMainCust = getApp().globalData.stdOffsurConstructionMainCust
				this.mllForm = getApp().globalData.stdOffsurConstructionMargin
			}, getApp().globalData.timeout)
		},
		methods: {
			lvhj() {
				if (this.mllForm.length == 2) {
					this.mllHj.turnover12month = Number(this.mllForm[0].turnover12Month) + Number(this.mllForm[1].turnover12Month)
					this.mllHj.invoice12month = Number(this.mllForm[0].invoice12month) + Number(this.mllForm[1].invoice12month)
					this.mllHj.materialCost = Number(this.mllForm[0].materialCost) + Number(this.mllForm[1].materialCost)
					this.mllHj.labourCost = Number(this.mllForm[0].labourCost) + Number(this.mllForm[1].labourCost)
					this.mllHj.affiliationCost = Number(this.mllForm[0].affiliationCost) + Number(this.mllForm[1].affiliationCost)
					this.mllHj.otherCost = Number(this.mllForm[0].otherCost) + Number(this.mllForm[1].otherCost)
					//this.mllHj.marginRate=((1-(this.mllHj.invoice12month+this.mllHj.materialCost+this.mllHj.labourCost+this.mllHj.affiliationCost+this.mllHj.otherCost)/this.mllHj.turnover12month)*100).toFixed(2)
					//console.log('a'+this.mllForm[0].marginRate,'b'+this.mllForm[1].marginRate)

					let a = (Number(this.mllForm[0].turnover12Month) / this.mllHj.turnover12month * this.mllForm[0].marginRate).toFixed(
						2)
					let b = (Number(this.mllForm[1].turnover12Month) / this.mllHj.turnover12month * this.mllForm[1].marginRate).toFixed(
						2)

					if (a === 'NaN') {
						a = 0
					}
					if (b === 'NaN') {
						b = 0
					}

					let c = Number(a) + Number(b)
					//console.log(a, b, c)
					setTimeout(() => {
						//debugger
						this.mllHj.marginRate = c.toFixed(2)
					}, 0)
					
					getApp().globalData.total.stdOffsurConstructionMargin = this.mllHj

				}
			},
			add() {
				if (this.stdOffsurConstructionProject.length > 2) {
					uni.showToast({
						title: '已添加三条信息，无法继续增加',
						icon: "none",
						duration: 2000
					})
					return false
				}
				this.stdOffsurConstructionProject.push({
					businessId: "", //业务申请流水号
					contractComp: "", //发包企业
					contractCompTye: "", //发包企业类型
					cooperationYear: 0, //与客户合作年限
					createTime: "", //创建时间
					createUser: "", //创建人
					customerId: "", //客户编号
					customerSystemId: "", //客户系统编号
					deleteFlag: "", //删除标志
					entId: "", //企业ID
					entityRoleType: "", //数据归属类型
					finishRatio: 0, //完成进度（%）
					getDatTime: "", //数据加载时间
					imageUrl: "", //影像路径
					measuredFunds: 0, //已计量工程款（元）
					notReceivedFunds: 0, //未收工程款（元）
					projectName: "", //项目名称
					projectPeriod: 0, //项目工期（月）
					receivedFunds: 0, //已收工程款（元）
					reqId: "", //业务申请序号
					settlement: "", //结算方式
					sourceSystem: "", //数据来源系统
					surplusAmount: 0, //剩余合同金额（元）
					updateTime: "", //更新时间
					updateUser: "", //更新人
					uuid: "" //uuid
				})
			},
			adds() {
				if (this.stdOffsurConstructionMainCust.length > 2) {
					uni.showToast({
						title: '已添加三条信息，无法继续增加',
						icon: "none",
						duration: 2000
					})
					return false
				}
				this.stdOffsurConstructionMainCust.push({
					accountPeriod: 0, //账期（月）
					businessId: "", //业务申请流水号
					cooperationYear: 0, //合作年限（月）
					count12month: 0, //近12个月交易数量
					createTime: "", //创建时间
					createUser: "", //创建人
					custName: "", //客户名称
					customerId: "", //客户编号
					customerSystemId: "", //客户系统编号
					deleteFlag: "", //删除标志
					entId: "", //企业ID
					entityRoleType: "", //数据归属类型
					getDatTime: "", //数据加载时间
					imageUrl: "", //影像路径
					reqId: "", //业务申请序号
					settlement: "", //结算方式
					sourceSystem: "", //数据来源系统
					transaction: "", //交易产品
					turnover12month: 0, //近12个月交易金额（元）
					updateTime: "", //更新时间
					updateUser: "", //更新人
					uuid: "", //uuid
					xh: this.stdOffsurConstructionMainCust.length + 1 //序号
				})
			}

		}
	}
</script>

<style lang="scss">


</style>
